<?php

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\model\Banner as BannerModel;
use app\api\validate\IDMustBePositiveInt;
use app\api\exception\MissException;

class Banner extends BaseController
{

    /**
     * 获取Banner信息
     * @url     /banner/:id
     * @http    get
     * @param   int $id banner id
     * @return  array of banner item , code 200
     * @throws  MissException
     */
    public function getBanner($id)
    {
        $validate = new IDMustBePositiveInt();
        $validate->goCheck();
        $banner_model = BannerModel::getBannerById($id);
        if (empty($banner_model))
        {
            $res = [
                'msg' => '请求banner不存在',
                'errorCode' => 40000
            ];
            $exception = new MissException($res);
            throw $exception;
        }
        return $banner_model;
    }

}
